package bz.yfw.example.s3blazeds.part1.behavior
{
	import bz.yfw.example.s3blazeds.part1.helper.TopHelper;
	import bz.yfw.example.s3blazeds.part1.validator.TopValidator;
	
	import org.seasar.akabana.yui.framework.ns.handler;
	
	import spark.components.RadioButtonGroup;

	public class TopBehavior
	{
		public var helper:TopHelper;
		
		public var topValidator:TopValidator;
		
		public var rdBtnGrup:RadioButtonGroup;
		
		handler function on_viewInitialized():void{
			topValidator.init();
			helper.initRadioButton();
		}
	
		handler function txtinptText_change():void {
			doExecuteTextInputEmpty();
		}
		
		handler function rdBtnGrup_change():void {
			doExecuteTextInputEmpty();
		}
		
		private function doExecuteTextInputEmpty():void {
			var inputText:String = helper.inputText;
			var selectedRadioButton:String = helper.selectedRadioValue;
			
			var isError:Boolean = 
				!topValidator.validate() && selectedRadioButton != "get";
			
			if (isError) {
				helper.doError();
			} else {
				helper.doError(false);
			}
		}
	}
}